package com.springboot.frame.starter.web.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;

/**
 * @author liheng
 * @ClassName TimeRangePageDTO
 * @Description
 * @date 2021-05-24 14:42
 */
@ApiModel("时间范围分页dto")
public class TimeRangePageDTO extends BasePageDTO {
    @ApiModelProperty("开始时间 格式 yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private LocalDate startTime;

    @ApiModelProperty("结束时间 格式 yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private LocalDate endTime;

    public String getStartTime() {
        if (Objects.nonNull(startTime)) {
            return LocalDateTime.of(startTime, LocalTime.parse("00:00:00")).format(DateTimeFormatter.ofPattern(BasePageDTO.DATE_FORMATTER_TIME));
        }
        return null;
    }

    public void setStartTime(LocalDate startTime) {
        this.startTime = startTime;
    }

    public String getEndTime() {
        if (Objects.nonNull(endTime)) {
            return LocalDateTime.of(endTime, LocalTime.parse("23:59:59")).format(DateTimeFormatter.ofPattern(BasePageDTO.DATE_FORMATTER_TIME));
        }
        return null;
    }

    public void setEndTime(LocalDate endTime) {
        this.endTime = endTime;
    }

    @Override
    public String toString() {
        return super.toString()+"TimeRangePageDTO{" +
                "startTime=" + startTime +
                ", endTime=" + endTime +
                '}';
    }
}
